/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sda.levelup.rating;

import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeMap;
import sda.levelup.library.FileMaster;
/**
 *
 * @author Дима
 */
public class RatingWorker
{    
    private TreeMap<User, Integer> tmap;
    private LinkedList<String> list;
    private int page=1;
    private int counter=0;

    public RatingWorker() {
        tmap = new TreeMap<User, Integer>(new RatingComparator());
        list = new LinkedList<String>();
    }
    
    public void addUser(User user){
        counter++;
        if(counter%5==0){
           page++; 
        }
        user.setPage(page);
        list.add(user.toString());
        tmap.put(user, user.getId());
        FileMaster.addToFile(user, "D:\\Courses\\Rating.txt");        
    }
    public void addUser(String u){        
        StringTokenizer st = new StringTokenizer(u, "-");
        int id = Integer.parseInt(st.nextToken());
        int rating = Integer.parseInt(st.nextToken());
        User user = new User(id, rating);
        addUser(user);
    }
    public int getRating(int id){
        
        return 5;
    }
    
    public void topFive(){
        User temp = tmap.lastKey();
        System.out.println(tmap.floorKey(temp));
        /*User next;
        for (int i=0; i<5; i++){
            System.out.println(temp);
            temp = tmap.floorKey(temp);                     
       }    */          
    }
    
    
    
}
